package servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.Pessoa;
import fachada.Fachada;

public class RemoverAmigo extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2325703548527758768L;

	@Override
	protected void doGet(HttpServletRequest request, 
						  HttpServletResponse response)
						  throws ServletException, IOException {
		
		Fachada f = new Fachada();
		HttpSession session = request.getSession();
		Pessoa p = (Pessoa) session.getAttribute("pessoa");
		
		Pessoa a = new Pessoa();
		a.setEmail(request.getParameter("email"));
		
		
		if(f.removerAmigo(p, a)){
			RequestDispatcher rd = request.getRequestDispatcher("pages_errors_sucess/sucesso_remover_amigo.html");
			p = f.consultar(p);
			session.setAttribute("pessoa", p);
			rd.forward(request, response);
		}else {
			response.sendRedirect("pages_errors_sucess/erro_remover_amigo.html");
		}
		
	}
	
}
